from django.db import models
from login.models import *
from db.base_models import BaseModel
from goods.models import *
# Create your models here.


class OrderInfo(BaseModel):
    """
    订单信息
    """
    PAY_METHOD = ((1, "货到付款"), (2, "微信支付"), (3, "支付宝"), (4, "银联支付"))
    ORDER_STATUS = ((1, "待支付"), (2, "待发货"), (3, "待收货"), (4, "待评价"), (5, "已完成"))
    order_id = models.CharField(max_length=128, primary_key=True, verbose_name='订单id')
    user = models.ForeignKey(User, verbose_name='用户', on_delete=models.CASCADE)
    addr = models.ForeignKey(Address, verbose_name='地址', on_delete=models.CASCADE)
    pay_method = models.SmallIntegerField(choices=PAY_METHOD, default=3, verbose_name='支付方式')
    total_count = models.IntegerField(default=1, verbose_name='总数量')
    total_price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='总价格')
    transit_price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='邮费')
    order_status = models.SmallIntegerField(choices=ORDER_STATUS, default=1, verbose_name='订单状态')
    # 支付宝支付完成后,会返回一个支付编号
    trade_no = models.CharField(max_length=128, verbose_name='支付编号')

    class Meta:
        db_table = 'order_info'
        verbose_name = '订单信息表'
        verbose_name_plural = verbose_name


class OrderGoods(BaseModel):
    """
    订单商品模型类
    """
    order = models.ForeignKey(OrderInfo, on_delete=models.CASCADE, verbose_name='订单', )
    sku = models.ForeignKey(Goods, on_delete=models.CASCADE, verbose_name='商品')
    count = models.IntegerField(default=1, verbose_name='商品数目')
    price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='商品价格')
    comment = models.CharField(max_length=256, verbose_name='评论')

    class Meta:
        db_table = 'order_goods'
        verbose_name = '订单商品表'
        verbose_name_plural = verbose_name
